# -*- coding:utf-8 -*-
# -------------------------------------------------------------------------------
# Description:  
# Reference:
# Author: 安智军
# Date:   2021/11/29
# -------------------------------------------------------------------------------
import time
from PageLocators.PagePurchaseReceiptOrderLoc import PurchaseReceiptOrderPageLoc as loc
from Common.Base import Base
from Common.GetLog import GetLog

log = GetLog.get_logger()


class PurchaseReceiptorder(Base):
    # 采购入库订单 创建订单
    def page_switch_warehouse(self):
        '''
        登录成功后点击切换仓库切换到作业端
        :return:
        '''
        log.info("点击切换仓库")
        print("点击切换仓库")
        time.sleep(3)
        self.base_click(loc.Switch_warehouse)

    def page_click_choose_warehouse_btn(self):
        '''
        选择仓库元素
        :return:
        '''
        log.info("点击请选择")
        print("点击请选择")
        time.sleep(1)
        self.base_click(loc.click_choose_warehouse_btn)
        time.sleep(2)

    def page_click_choose_warehouse(self):
        '''
        选择仓库
        :return:
        '''
        log.info('选择仓库')
        print('选择仓库')
        time.sleep(2)
        self.base_click(loc.click_choose_warehouse)
        time.sleep(1)

    def page_enter_warehose(self):
        '''
        点击进入仓库
        :return:
        '''
        log.info("点击进入仓库")
        print("点击进入仓库")
        time.sleep(3)
        self.base_click(loc.Enter_warehouse_btn)

    def page_click_menu(self):
        '''
        点击菜单进入菜单
        :return:
        '''
        log.info("正在点击菜单")
        time.sleep(3)
        print("正在点击菜单")
        self.base_click_hamber_btn(loc.click_menu_btn)
        time.sleep(3)

    def page_click_Order_management(self):
        '''
        点击订单管理
        :return:
        '''
        log.info("点击订单管理")
        time.sleep(1)
        print("正在点击订单管理")
        self.base_click(loc.click_Order_management_menu)
        time.sleep(1)

    def page_click_enter_Purchase_warehousing(self):
        '''
        点击进入采购入库订单
        :return:
        '''
        log.info("点击进入采购入库订单")
        self.base_click(loc.click_Purchase_receipt_order_menu)
        time.sleep(1)

    def page_click_Purchase_receipt_order_btn(self):
        '''
        点击创建采购单按钮
        :return:
        '''
        log.info("点击创建采购单按钮")
        self.base_click(loc.click_Purchase_receipt_order_btn)
        time.sleep(1)

    # 采购单基本信息
    def page_choose_Document_type_owner_Supplier(self):
        '''
        选择单据类型、货主名称、供应商
        :return:
        '''
        log.info("点击选择单据类型：采购入库")
        self.base_click(loc.click_Document_type_ele)
        time.sleep(2)
        self.base_click(loc.click_choose_Document_type)  # 单据类型为采购入库
        time.sleep(1)

        log.info("点击选择货主名称：UI自动化测试")
        self.base_click(loc.click_Owner_name)
        time.sleep(2)
        self.base_click(loc.click_choose_Owner_name)  # 选择货主名称：UI自动化测试
        time.sleep(1)

        log.info("点击选择供应商名称：UI供应商")
        self.base_click(loc.click_Supplier_name)
        time.sleep(2)
        self.base_click(loc.click_choose_Supplier_name)  # 供应商名称：UI供应商
        time.sleep(1)

    def input_ExternalPoNo_remark(self,ExternalPoNo,Purchase_order_remark):
        '''
        输入外部采购单号、备注信息
        :return:
        '''

        log.info("输入外部采购单号")
        time.sleep(1)
        self.base_input(loc.ExternalPoNo_ele,ExternalPoNo) # 输入外部采购单号
        time.sleep(1)

        log.info("输入外部采购单备注信息")
        time.sleep(1)
        self.base_input(loc.Purchase_order_remark_ele,Purchase_order_remark) # 输入外部采购单号

    def add_goods(self,goodsnum):
        '''
        点击选择商品，选择商品数量
        :return:
        '''

        log.info("点击添加商品")
        time.sleep(1)
        self.base_click(loc.click_addgoods_btn)
        time.sleep(1)

        log.info("点击商品名称并选择商品")
        self.base_click(loc.click_goodsname)
        time.sleep(1)
        self.base_click(loc.click_choose_goodsname)
        time.sleep(1)

        log.info("输入商品数量")
        self.base_input(loc.input_goodsnum,goodsnum)
        time.sleep(1)

        log.info("点击“保存并添加下一条按钮”")
        self.base_click(loc.click_save_goods)
        time.sleep(1)

        log.info("点击关闭按钮")
        self.base_click(loc.click_close_ele)
        time.sleep(1)

        log.info("点击保存并创建采购单")
        self.base_click(loc.click_and_create_Purchase_order)
        time.sleep(1)

    def search_Purchase_order_No(self):

        log.info("点击重置按钮")
        self.base_click(loc.Reset_btn)
        time.sleep(1)

        log.info("点击搜索按钮")
        self.base_click(loc.srarch_btn)
        time.sleep(1)

        log.info("获取最新的采购订单单号")
        Purchase_order_No = self.base_get_element_text(loc.Purchase_order_No)
        log.info(f"获取最新的采购订单单号:{Purchase_order_No}")
        print("获取最新的采购订单单号:{}".format(Purchase_order_No))
        time.sleep(1)

        log.info("点击输入采购单号")
        self.base_input(loc.input_Purchase_order_No,Purchase_order_No)
        time.sleep(1)

        log.info("输入采购单号点击搜索")
        self.base_click(loc.Purchase_order_No_srarch_btn)
        time.sleep(1)
        return Purchase_order_No

    def Get_External_Po_No_text(self):
        '''
         获取外部采购单号用来断言
        :return:
        '''
        log.info("获取外部采购单号用来断言")
        return self.base_get_element_text(loc.assert_External_Po_No)

    def Get_remark_text(self):
        '''
         获取输入的备注内容用来断言
        :return:
        '''
        log.info("获取输入的备注内容用来断言")
        return self.base_get_element_text(loc.assert_remark)

    def Get_goods_num_text(self):
        '''
         获取商品数量用来断言
        :return:
        '''
        log.info("获取商品数量用来断言")
        return self.base_get_element_text(loc.assert_goods_num)

    def Get_sku_num_text(self):
        '''
         获取sku数量用来断言 不为空即可
        :return:
        '''
        log.info("获取sku数量用来断言")
        return self.base_get_element_text(loc.assert_sku_num)

    def Get_Warehouse_name_text(self):
        '''
         断言仓库名称不为空
        :return:
        '''
        log.info("获取仓库名称用来断言")
        return self.base_get_element_text(loc.assert_Warehouse_name)

    def audit_Purchase_order(self):
        '''
        审核采购入库订单
        :return:
        '''
        log.info("勾选选择第一条数据")
        self.base_click(loc.Selection_box_btn)
        time.sleep(1)

        log.info("点击一键审核")
        self.base_click(loc.One_click_audit)
        time.sleep(1)

        log.info("一键审核-确定")
        self.base_click(loc.Audit_confirm)
        time.sleep(1)


    #########  【入库管理-标准验收】 #######

    def Acceptance_of_the_goods(self,External_Po_No):
        '''
        验收商品
        :return:
        '''
        log.info("点击入库管理菜单")
        self.base_click(loc.click_Warehousing_management_menu)
        time.sleep(1)

        log.info("点击收货入库菜单")
        self.base_click(loc.click_Receipt_and_warehousing_menu)
        time.sleep(1)

        log.info("点击重置按钮")
        self.base_click(loc.The_goods_warehouse_reset)
        time.sleep(1)

        log.info("在订单单号输入框输入采购单号")
        # self.base_input(loc.input_The_rder_number,self.Get_External_Po_No_text())
        self.base_input(loc.input_The_rder_number,External_Po_No)
        time.sleep(1)

        log.info("点击搜索")
        self.base_click(loc.The_goods_warehouse_search)
        time.sleep(1)

        log.info("点击验收按钮 进入标准验收页面")
        self.base_click(loc.click_acceptance)
        time.sleep(2)

        # log.info("关闭标准验收页面")
        # self.base_click(loc.close_acceptance_btn)

        log.info("点击收货入库菜单")
        self.base_click(loc.click_Receipt_and_warehousing_menu)
        time.sleep(2)

        log.info("再次点击验收按钮 进入标准验收页面")
        self.base_click(loc.click_acceptance)
        time.sleep(3)


        # time.sleep(1)
        #
        log.info("勾选商品")
        self.base_click(loc.click_tick_goods)
        time.sleep(1)

        log.info("点击本次验收")
        self.base_click(loc.click_this_acceptance)
        time.sleep(1)


    def check_acceptance_staus(self,External_Po_No):
        '''
        检查验收后验收后订单的状态
        :return:
        '''

        log.info("点击重置按钮")
        self.base_click(loc.The_goods_warehouse_reset)
        time.sleep(1)

        log.info("在订单单号输入框输入采购单号")
        self.base_input(loc.input_The_rder_number,External_Po_No)
        time.sleep(1)

        log.info("点击搜索")
        self.base_click(loc.The_goods_warehouse_search)
        time.sleep(1)

    def get_Receipt_no_text(self):
        '''
         获取已完验的入库单号
        :return:
        '''
        log.info("获取已完验的入库单号")
        global Receipt_no
        Receipt_no = self.base_get_element_text(loc.Receipt_no)
        return Receipt_no

    def get_Purchase_status_text(self):
        '''
        获取采购订单验收成功后的状态
        :return:
        '''
        log.info("获取采购订单验收成功后的状态用来断言")
        return self.base_get_element_text(loc.assert_is_Complet_acceptance)



    def Paper_sheet_shelves(self, Actual_shelf_position, goods_num):
        '''
        纸单上架流程
        :return:
        '''

        log.info("点击纸单上架")
        self.base_click(loc.click_Paper_sheet_shelves_menu)
        time.sleep(1)

        log.info("点击重置")
        self.base_click(loc.Paper_sheet_shelves_reset)
        time.sleep(1)

        log.info(f"输入入库单号:{Receipt_no}")
        self.base_input(loc.input_Receipt_no,Receipt_no)
        self.base_input(loc.input_Receipt_no,Receipt_no)
        time.sleep(1)
        #
        log.info("点击搜索该入库单号")
        self.base_click(loc.click_search_input_Receipt_no)
        time.sleep(1)

        log.info("点击上架按钮")
        self.base_click(loc.click_shelves_btn)
        time.sleep(1)


        log.info("输入实际上架库位")
        self.base_input(loc.input_Actual_shelf_position,Actual_shelf_position)
        time.sleep(1)

        # log.info("获取应上架数量的值")
        # get_Should_be_on_num_value = self.base_get_element_text(loc.get_Should_be_on_num_value)
        # time.sleep(1)

        log.info("将获取应上架数量的值输入到实际上架数量的位置")
        self.base_input(loc.input_actual_should_be_on,goods_num)
        time.sleep(1)

        log.info("点击上架确认")
        self.base_click(loc.click_shelves_confirm)
        time.sleep(1)

        log.info("点击重置")
        self.base_click(loc.Paper_sheet_shelves_reset)
        time.sleep(1)

        log.info(f"输入入库单号:{Receipt_no}")
        self.base_input(loc.input_Receipt_no,Receipt_no)
        time.sleep(1)

        log.info("点击搜索该入库单号")
        self.base_click(loc.click_search_input_Receipt_no)
        time.sleep(15)

    def get_shelves_status_text(self):
        log.info("获取已上架状态")
        return self.base_get_element_text(loc.assert_shelves_status)


    def shelves_details(self):
        '''
        检查已上架明细中的内容
        :return:
        '''

        log.info("点击查看明细")
        self.base_click(loc.click_watch_detail)
        time.sleep(1)

        log.info("断言实际上架中的内容")
        self.base_click(loc.click_detail_close)
        time.sleep(1)



    def Page_element_execution_order(self):
        '''
        页面用例执行顺序
        :return:
        '''
        time.sleep(1)
        self.page_click_menu() # 点击菜单
        self.page_click_Order_management() # 点击订单管理 （默认点击订单管理）


